import Article from "@/views/Article.vue";
import ArticleDetail from "@/views/ArticleDetail.vue";
import Collect from "@/views/Collect.vue";
import Layout from "@/views/Layout.vue";
import Like from "@/views/Like.vue";
import Login from "@/views/Login.vue";
import NotFound from "@/views/NotFound.vue";
import Register from "@/views/Register.vue";
import User from "@/views/User.vue";
import Vue from "vue";
import VueRouter from "vue-router";

Vue.use(VueRouter);

const router = new VueRouter({
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition;
    } else {
      return { x: 0, y: 0 };
    }
  },
  routes: [
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/login",
      name: "login",
      component: Login,
    },
    {
      path: "/register",
      name: "register",
      component: Register,
    },
    {
      path: "/article",
      redirect: "/layout/article",
    },
    {
      path: "/collect",
      redirect: "/layout/collect",
    },
    {
      path: "/like",
      redirect: "/layout/like",
    },
    {
      path: "/user",
      redirect: "/layout/user",
    },
    {
      path: "/layout",
      name: "layout",
      component: Layout,
      children: [
        {
          path: "/layout/article",
          name: "article",
          component: Article,
        },
        {
          path: "/layout/collect",
          name: "collect",
          component: Collect,
        },
        {
          path: "/layout/like",
          name: "like",
          component: Like,
        },
        {
          path: "/layout/user",
          name: "user",
          component: User,
        },
      ],
    },
    {
      path: "/detail/:id",
      name: "detail",
      component: ArticleDetail,
    },
    {
      path: "*",
      component: NotFound,
    },
  ],
});

export default router;
